package borderPatrol.misc;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.Stack;

/**
 * Static class for cloning 2-D arrays
 * 
 * @author Jiri Cermak
 *
 */
public class Cloner {

	public static byte[][] clone(byte[][] source, byte[][] destination) {
		for (int i = 0; i < destination.length; i++) {
			for (int j = 0; j < destination[0].length; j++) {
				destination[j][i] = source[j][i];
			}
		}

		return destination;
	}

	public static int[][] clone(int[][] source, int[][] destination) {
		for (int i = 0; i < destination.length; i++) {
			for (int j = 0; j < destination[0].length; j++) {
				destination[j][i] = source[j][i];
			}
		}

		return destination;
	}

	public static byte[][] clone(byte[][] source) {

		byte[][] destination = new byte[source[0].length][source.length];

		for (int i = 0; i < destination.length; i++) {
			for (int j = 0; j < destination[0].length; j++) {
				destination[j][i] = source[j][i];
			}
		}

		return destination;
	}

	public static int[][] clone(int[][] source) {

		int[][] destination = new int[source[0].length][source.length];

		for (int i = 0; i < destination.length; i++) {
			for (int j = 0; j < destination[0].length; j++) {
				destination[j][i] = source[j][i];
			}
		}

		return destination;
	}
	
	public static Stack<int[][]> clone(Stack<int[][]> source) {
		
		Stack<int[][]> stack = new Stack<int[][]>();
		Iterator<int[][]> iterator = source.iterator();
		
		while(iterator.hasNext()) {
			stack.push(clone(iterator.next()));
		}
		
		return stack;
	}
	
	public static LinkedList<int[]> clone(LinkedList<int[]> source) {
		
		LinkedList<int[]> list = new LinkedList<int[]>();
		
		for (int[] item : source) {
			list.add(item.clone());
		}
		
		return list;
	}
	
	public static LinkedList<History> cloneHistories(LinkedList<History> source) {
		
		LinkedList<History> history = new LinkedList<History>();

		for (History item : source) {
			history.add(item.clone());
		}
		
		return history;
	}
}
